package cn.com.nes.site.controller.product;

import cn.com.nes.common.util.Globals;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.entity.vo.product.GGoodsVO;
import cn.com.nes.site.service.product.GGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 商品（产品）维护Controller，添加产品到g_goods表，推送t_sblx表
 *
 * @Author: ShenWei
 * @Date: 2024/04/01/14:02
 */
@Controller
@RequestMapping("/v2/product/goods")
@Api(tags = {"产品管理-产品管理"})
public class GGoodsController {
    @Resource
    GGoodsService gGoodsService;

    @ApiOperation("查询商品表g_goods的参数字段")
    @RequestMapping(value = "/getParamFields", method = RequestMethod.GET)
    @ResponseBody
    public PageData getParamFields(GGoodsVO vo) {
        String dbName = Globals.DBNAME; // 获取数据库名称
        return gGoodsService.getParamFields(dbName);
    }

    @ApiOperation("保存产品信息")
    @ResponseBody
    @RequestMapping(value = "/saveGoods", method = RequestMethod.POST)
    public PageData saveGoods(@RequestBody GGoodsVO vo) {
        return gGoodsService.saveGoods(vo);
    }

    @ApiOperation("产品列表-分页查询")
    @ResponseBody
    @RequestMapping(value = "/getGoodsPage", method = RequestMethod.GET)
    public PageData getGoodsPage(GGoodsVO vo) throws Exception {
        return gGoodsService.getGoodsPage(vo);
    }

    @ApiOperation("查询产品详情")
    @ResponseBody
    @RequestMapping(value = "/getGoodsDetail", method = RequestMethod.GET)
    public PageData getGoodsDetail(GGoodsVO vo) throws Exception {
        return gGoodsService.getGoodsDetail(vo);
    }

    @ApiOperation("删除产品")
    @ResponseBody
    @RequestMapping(value = "/delGoods", method = RequestMethod.POST)
    public PageData delGoods(@RequestBody GGoodsVO vo) {
        return gGoodsService.delGoods(vo);
    }
}
